<?php

namespace app\admin\controller;

use app\admin\model\Menu;
use com\Permission;
use think\Controller;

class Main extends Controller{

    public function index(){
        $dataObj = Menu::all(function($query){
            $query->order('sort', 'asc');
        });

        $authList = (new Permission())->getAuthList($this->uid);
        $data=[];
        foreach ($dataObj as $value){
            if( !$value->hide ){
                if( isAdministrator() ){
                    $data[] = $value->toArray();
                }else{
                    if( (isset($authList[$value->url]) && $authList[$value->url]) || empty($value->url) ){
                        $data[] = $value->toArray();
                    }
                }
            }
        }

        //环境信息
        $info = array(
            'web_server' => $_SERVER['SERVER_SOFTWARE'],
            'onload'     => ini_get('upload_max_filesize'),
            'think_v'    => THINK_VERSION,
            'phpversion' => phpversion(),
        );
        $this->assign('info',$info);

        $data = listToTree($data);

        $this->assign('title', '首页');
        $this->assign('menuData', $data);
        cache('menu_data',$data);
        $this->assign('userInfo', $this->userInfo);
        return $this->fetch();
    }
}